unit DBBaseRpt;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBClient, alBaseDataSet, MConnect, PoslovanjeSrv_TLB, BaseRpt;

type
  TSessionParamRelation = record
    FieldName: string;
    SessionName: string;
  end;

  TSessionParamRelations = array of TSessionParamRelation;
  
  TrptDBBase = class(TrptBase)
    scnMain: TSharedConnection;
    cdsMain: TBaseDataSet;
    dtsrcMain: TDataSource;
    procedure BeforeOpen(DataSet: TDataSet);
  private
    function GetMainServer: IrdmMain;
    { Private declarations }
  protected
    function GetRazredID(DataSet: TClientDataSet): Integer;
    function GetSessionParamRelations(DataSet: TDataSet): TSessionParamRelations; virtual;
    function GetSelectCommandText(DataSet: TDataSet): string; virtual;
    procedure Deinitialize; override;
    procedure Initialize; override;
  public
    property MainServer: IrdmMain read GetMainServer;
  end;

implementation

{$R *.dfm}

{ TrptDBBase }

procedure TrptDBBase.BeforeOpen(DataSet: TDataSet);
var
  i: Integer;
  SessionFieldNames: TSessionParamRelations;
begin
  SessionFieldNames := GetSessionParamRelations(DataSet);
  with DataSet as TBaseDataSet do
  begin
    for i := 0 to High(SessionFieldNames) do
    begin
      Params.ParamByName(SessionFieldNames[i].SessionName).Value :=
        Session.Params[SessionFieldNames[i].SessionName];
    end;
  end;  
end;

procedure TrptDBBase.Deinitialize;
begin
  cdsMain.Close;
  inherited;
end;

function TrptDBBase.GetMainServer: IrdmMain;
begin
  Result := (scnMain.ParentConnection.GetServer) as IrdmMain;
end;

function TrptDBBase.GetRazredID(DataSet: TClientDataSet): Integer;
begin
  Result := (DataSet.AppServer as IrdmObjekt).RazredID[DataSet.ProviderName];
end;

function TrptDBBase.GetSelectCommandText(DataSet: TDataSet): string;
begin

end;

function TrptDBBase.GetSessionParamRelations(
  DataSet: TDataSet): TSessionParamRelations;
begin

end;

procedure TrptDBBase.Initialize;
begin
  inherited;
  cdsMain.SQLFilter := FSQLFilter;
  cdsMain.Open;
end;

end.
